package com.xpgk.mvc.collection.binShopService;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.xpgk.mvc.base.BaseController;
import com.xpgk.mvc.bentryRegister.Customer;
import com.xpgk.mvc.bentryRegister.CustomerDetail;
import com.xpgk.mvc.codeSet.Code;
import com.xpgk.mvc.productOrgExperience.ProductOrgExperience;
import com.xpgk.mvc.productSet.Product;
import com.xpgk.tools.ToolDateTime;

public class UpdateServicesController extends BaseController{
	public void index(){
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("column", Product.column_typeIds);
		String sql = getSqlByBeetl(Product.sqlId_column, param);
		setAttr("plaster", Product.dao.find(sql, Code.proYt_ids));
		setAttr("organids", getCUserOrganIds());
		String date = getPara("date");
		if(date==null||date.equals("")){
			setAttr("date", new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
		}else{
			setAttr("date",date);
		}
		
		String sqlbb = "SELECT * FROM sb_product_orgexperience where organIds =? and bbExperience IS NOT NULL and dataStatus = '1'";
		String sqlkb = "SELECT * FROM sb_product_orgexperience where organIds =? and kbExperience IS NOT NULL and dataStatus = '1'";
		String sqlfr = "SELECT * FROM sb_product_orgexperience where organIds =? and frExperience IS NOT NULL and dataStatus = '1'";
		ProductOrgExperience bb = ProductOrgExperience.dao.findFirst(sqlbb,getCUserOrganIds());
		int n = 4;
		if(bb!=null){
			n++;
			setAttr("bbExp", "1");
		}else{
			setAttr("bbExp", "0");
		}
		ProductOrgExperience kb = ProductOrgExperience.dao.findFirst(sqlkb,getCUserOrganIds());
		if(kb!=null){
			n++;
			setAttr("kbExp", "1");
		}else{
			setAttr("kbExp", "0");
		}
		ProductOrgExperience fr = ProductOrgExperience.dao.findFirst(sqlfr,getCUserOrganIds());
		if(fr!=null){
			n = n+2;
			setAttr("Exp", "1");
		}else{
			setAttr("Exp", "0");
		}
		setAttr("partnum",n);
		render("/collection/binShopService/BinShopService1.html");
	}
	
	public void toUpdate(){
		String cusIds = getPara("ids");
		
		String date = getPara("date");
		
		Record cs = Db.findFirst("select a.*,sys_getUserName(a.plasterServier) sf  ,sys_getUserName(b.yb) yb , sys_getUserName(b.dt) dt, sys_getUserName(b.xt) xt, sys_getUserName(b.gb) gb  ,sys_getUserName(b.bb) bb  ,sys_getUserName(b.kb) kb ,sys_getUserName(b.zfr) zfr ,sys_getUserName(b.yfr) yfr from sb_customer_service  a left join  sb_customer_service_shaping  b on a.ids=b.serviceIds  where a.startTime=? and  a.customerID = ?",date,cusIds);
		setAttr("customerService", cs);
		
		setAttr("customerIds", cusIds);
		setAttr("startTime", date);
		render("/collection/binShopService/BinShopService1.html");
	}

}
